package com.my.study.anno.driven.conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author Carlos
 * @version 1.0
 * @Description 判断是否为linux系统
 * @date 2021/11/23 7:46
 **/
public class LinuxCondition implements Condition {

    /**
     *
     * @param context
     * @param metadata
     * @return
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        String osName = environment.getProperty("os.name");
        if (osName != null && osName.contains("linux")) {
            return true;
        }

        return false;
    }
}
